package com.my.jwt.shiro.thread;


import com.alibaba.fastjson.JSONObject;
import com.my.core.api.R;
import com.my.core.domain.exception.ServiceException;
import com.my.jwt.shiro.thread.domain.TFTBLoginParam;
import com.my.jwt.shiro.thread.service.TftbUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 天府通办
 */
//@RestController
//@RequestMapping("/tftb")
public class TianFuTongBanController {

    @Autowired
    private TftbUserService tftbUserService;

    /**
     * 天府通办 APP 小程序获取token
     * @param param
     * @return
     */
    @PostMapping("/login/token")
    public R login(@RequestBody TFTBLoginParam param){
        if (StringUtils.isEmpty(param.getIdNumber())){
            throw new ServiceException("idNumber 不能为空！");
        }
        if (StringUtils.isEmpty(param.getUsername())){
            throw new ServiceException("userName 不能为空!");
        }
        //
        String token  =  tftbUserService.login(param);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("token",token);
        return R.data(jsonObject);
    }


}
